#include <windows.h>
#include <psapi.h>

/* Hooks not used but required to include some kind of type definitions */
#include "TSfuncs/MinHookMini.h"

#include "TSfuncs/TSFuncs.cpp"
#include "TSfuncs/TSHooks.cpp"
#include "TSfuncs/TSVector.cpp"

#include "BLstructs/include.hpp"

const char* TS_GET_MEMORY(ADDR objADDR, int argc, const char *argv[])
{
	PROCESS_MEMORY_COUNTERS_EX pmc;
	GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS*)&pmc, sizeof(pmc));
	
	static char bytes[64];
	snprintf(bytes, 64, "%lu %lu", pmc.WorkingSetSize, pmc.PrivateUsage);
	return bytes;
}

bool init()
{
	if(!tsh_InitInternal())
		return false;
		
	if (!tsf_InitInternal())
		return false;
	
	tsf_AddConsoleFunc(NULL, NULL, "getMemoryUsage", TS_GET_MEMORY, "() - get the memory usage (WorkingSetSize and PrivateUsage as two words)", 1, 1);
	
	BlPrintf("%s (v%s-%s): init'd", PROJECT_NAME, PROJECT_VERSION, TSFUNCS_DEBUG ? "debug":"release");

	return true;
}

bool deinit(bool terminating)
{
	printf("%s: deinit'd\n", PROJECT_NAME);
	if(!terminating)
	{
		//No hooks to disable
	}

	return true;
}

bool __stdcall DllMain(HINSTANCE hinstance, int reason, void *reserved)
{
	switch (reason)
	{
		case DLL_PROCESS_ATTACH:
			return init();
		case DLL_PROCESS_DETACH:
			return deinit(reserved != NULL);
		default:
			return true;
	}
}

extern "C" void __declspec(dllexport) __cdecl PROJECT_EXPORT(){}
